package com.shop2cn.iapi.agentproducts.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.CategoryDto;
import com.shop2cn.iapi.agentproducts.parameter.QueryCategoryAndChannelsBean;
import com.shop2cn.iapi.agentproducts.service.QueryCategoryAndChannelsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.AgentUsers;

/**
*筛选项接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryCategoryAndChannels{
	private static QueryCategoryAndChannelsBean querycategoryandchannelsBean;
	private static QueryCategoryAndChannelsCall querycategoryandchannelsCall;
	private YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
	//渠道商
	private static int sellerId = AgentUsers.rootUserId;
	private static String sellerName = "NickautoTest";
	//渠道商->代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	private static String agentUserName1 = "NickautoTest";
	//渠道商->代理商2
	private static int agentUserId2 = AgentUsers.agentUserId2;
	private static String agentUserName2 = "NickautoTest";

	//vip渠道
	private static int vipRootUserId = AgentUsers.vipRootUserId;
	private static String vipRootUserName = "NickautoTest";
	//vip渠道->代理
	private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
	private static String vipAgentUserName1 = "dgsq408897016";
	//vip渠道->代理->代理
	private static int vipAgentUserId2 = AgentUsers.vipAgentUserId2;
	private static String vipAgentUserName2 = "NickautoTest";
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("筛选项接口");
	}

	@Before
	public void caseUp() {
		querycategoryandchannelsBean=new QueryCategoryAndChannelsBean();
		querycategoryandchannelsCall=new QueryCategoryAndChannelsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querycategoryandchannelsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	public void verifyDB(List<CategoryDto> categoryLists){
		categoryLists.forEach(p->{
			try {
				if (p.getCategoryId()!=0){
					com.shop2cn.iapi.agentproducts.parameter.Category category = ymtProductsIWapper.selectProductCategoryByCategoryIdV2(p.getCategoryId()).get(0);
					Logger.verifyEquals(true,p.getCategoryName().contains(category.getsCategory()),"验证categoryName");
					p.getChildList().forEach(x->{
						try {
							com.shop2cn.iapi.agentproducts.parameter.Category category1 = ymtProductsIWapper.selectProductCategoryByCategoryIdV2(x.getCategoryId()).get(0);
							Logger.verifyEquals(true,x.getCategoryName().contains(category1.getsCategory()),"验证categoryName");
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					});
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});

	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_QueryCategoryAndChannels_01() {
		Logger.start(true,"渠道商筛选");
		try {
			querycategoryandchannelsBean.setUserId(sellerId);
			querycategoryandchannelsCall.setData(querycategoryandchannelsBean);
			querycategoryandchannelsCall.callService();			
			Logger.verifyEquals("200",querycategoryandchannelsCall.getString("code"),"验证code");
			List<CategoryDto> categoryLists = querycategoryandchannelsCall.getCategoryList();
			verifyDB(categoryLists);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryCategoryAndChannels_02() {
		Logger.start(true,"代理商筛选");
		try {
			querycategoryandchannelsBean.setUserId(agentUserId1);
			querycategoryandchannelsCall.setData(querycategoryandchannelsBean);
			querycategoryandchannelsCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryCategoryAndChannels_03() {
		Logger.start(true,"vip代理商筛选");
		try {
			querycategoryandchannelsBean.setUserId(vipAgentUserId1);
			querycategoryandchannelsCall.setData(querycategoryandchannelsBean);
			querycategoryandchannelsCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryCategoryAndChannels_04() {
		Logger.start(true,"userid为空");
		try {
			querycategoryandchannelsCall.setData(querycategoryandchannelsBean);
			querycategoryandchannelsCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}